home *** CD-ROM | disk | FTP | other *** search
- on espalha num, maxX, maxY
- set lista = []
- repeat with i = 1 to num
- add lista, point(random(maxX),random(maxY))
- end repeat
- repeat with z = 1 to 4
- repeat with i = 1 to num
- repeat with j = 1 to num
- if i <> j then
- set a = getAt(lista,i)
- set b = getAt(lista,j)
- set a = repele(a,b, maxX, maxY, power(2,z)*10000)
- setAt(lista,i,a)
- end if
- end repeat
- end repeat
- end repeat
- return lista
- end
-
- on mediaLista lista
- set soma = 0.0
- repeat with i = 1 to count(lista)
- repeat with j = 1 to count(lista)
- if i <> j then
- set dx = float(the locH of getAt(lista,i) - the locH of getAt(lista,j))
- set dy = float(the locV of getAt(lista,i) - the locV of getAt(lista,j))
- set d = sqrt(dx*dx + dy*dy)
- set soma = soma + 1.0 / d
- end if
- end repeat
- end repeat
- set soma = soma / ( count(lista) * (count(lista)-1) )
- set soma = 1.0 / soma
- return soma
- end
-
- on repele a, b, maxX, maxY, forca
- set x = the locH of a
- set y = the locV of a
- set dx = float(distancia (x, the locH of b, maxX))
- if dx = 0.0 then set dx = random(2) * 2.0 - 3.0
- set dy = float(distancia (y, the locV of b, maxY))
- if dy = 0.0 then set dy = random(2) * 2.0 - 3.0
- set dist = dx * dx + dy * dy
- set new = sqrt(dist + forca)
- set dist = sqrt(dist)
-
- set x = the locH of b + dx * new / dist
- if x < 0 then set x = x + maxX
- else if x >= maxX then set x = x - maxX
- set y = the locV of b + dy * new / dist
- if y < 0 then set y = y + maxY
- else if y >= maxY then set y = y - maxY
- return point(x,y)
- end
-
- on distancia a, b, max
- if a - b > max / 2 then
- return a - (b + max)
- else if a - b < - max / 2 then
- return a + max - b
- else
- return a-b
- end if
- end
-
-